function clearbvqxobjects(olist)
% clearbvqxobjects  - issue ClearObject call on several objects
%
% FORMAT:       clearbvqxobjects(olist)
%
% Input fields:
%
%       olist       cell array with BVQXfile objects
%
% No output fields

% Version:  v0.7g
% Build:    9040222
% Date:     Apr-02 2008, 10:36 PM CEST
% Author:   Jochen Weber, SCAN Unit, Columbia University, NYC, NY, USA
% URL/Info: http://wiki.brainvoyager.com/BVQXtools

% argument check
if nargin ~= 1 || ...
   (~iscell(olist) && ...
    ~isa(olist, 'double') && ...
    ~isa(olist, 'BVQXfile')) || ...
    isempty(olist)
    return;
end

% for cell array iterate over cells
if iscell(olist)
    
    % prepare double list for alternative calling syntax
    nlist = ones(1, numel(olist));
    for c = 1:numel(olist)
        if isBVQXfile(olist{c})
            sfile = struct(olist{c});
            if numel(sfile) == 1
                nlist(c) = sfile.L;
            else
                alist = zeros(1, numel(sfile));
                for sc = 1:numel(sfile)
                    alist(sc) = sfile(sc).L;
                end
                nlist = [nlist, alist];
            end
        elseif iscell(olist{c})
            clearbvqxobjects(olist{c});
        end
    end
    
    % clear objects
    BVQXfile(0, 'clearobj', nlist);
    
% for double array
elseif isa(olist, 'double')
    BVQXfile(0, 'clearobj', olist);
        
% for BVQXfiles
else
    clearbvqxobjects({olist});
end
